#pragma once
#ifndef _LPE_RESMAN_XMLNODE_TREE_H_
#define _LPE_RESMAN_XMLNODE_TREE_H_

#include "core/core_utils.h"



class TiXmlNode;

namespace lpe{
	namespace resman{
		class XMLNodeTree{
			public:
				XMLNodeTree();
				~XMLNodeTree();
//#ifdef DEBUG
				/**
				 * Print the contents of this node, and call recursively their child nodes.
				 * Only for debug purposes
				 * @param prevTabs The track for the previous tab to indent the outputs.
				 */
				void printNodeTree(const std::string& prevTabs);
//#endif
				/**
				 * Reads a TiXmlNode, put the contents in its properties and calls recursivelly to its childs to read the child TiXmlNode
				 * @param node The node to be read
				 * @return True if is correcly readed and false in any other case.
				 */
				bool readNode(TiXmlNode* node);
				/**
				 * Get the node name.
				 * @return the node name
				 */
				std::string getNodeName() const;
				/**
				 * Search a XMLNodeTree that contains the name specified by parameter. If parameter is equal to curret data name, then it returns
				 * a reference to itself. If not found, this method applies the same search to each child linked until it is found. If not found, it returns null
				 * @param name The name that we are searching for
				 * @return A pointer to XMLNodeTree that has this name or null if not found.
				 */
				const XMLNodeTree* searchNodeNameRecursive(const std::string& name) const;
				/**
				 * Returns the node value as an string
				 * @return an string with the value of the node.
				 */
				std::string getNodeValueAsString() const;
				/**
				 * Returns the node value as a unsigned int
				 * @return the value of the node converted to unsigned int
				 */
				uint32_t getNodeValueAsUnsignedInt() const;
				/**
				 * Returns the node value as a int
				 * @return the value of the node converted to int
				 */
				int32_t getNodeValueAsInt() const;
				/**
				 * Returns the node value as a float
				 * @return the value of the node converted to float
				 */
				float getNodeValueAsFloat() const;
				/**
				 * Returns the node value as a bool
				 * @return true if the value of the node is exactly true(case insensitive). False in any other case.
				 */
				bool getNodeValueAsBool() const;

				uint32_t getNumberOfChilds() const;
				XMLNodeTree* getChildNodeAt(uint32_t idx);
				XMLNodeTree* getChildNodeByName(const std::string& name);

				uint32_t getNumberOfAttributes() const;
				const std::map<std::string, std::string>& getAttributeMap();

				bool getAttributeValueByName(const std::string& attribName, std::string& value);
				std::string getAttributeValueByName(const std::string& attribName);


			private:
				std::string m_nodeName;
				std::string m_nodeText;
				uint32_t m_nAttributes;
				std::map<std::string, std::string> m_nodeAttributes;
				std::vector<XMLNodeTree*> m_childNodeList;
		};
	};
};

#endif //_LPE_RESMAN_XMLNODE_TREE_H_
